package com.mxwl.cbg.common.conversion;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.ZonedDateTime;

public class LocalDateTimeToEpochMillisSerializer extends JsonSerializer<ZonedDateTime> {



    @Override
    public void serialize(ZonedDateTime value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        if (value == null) {
            gen.writeNull();
        } else {
            long epochMilli = value.toInstant().toEpochMilli();
            gen.writeNumber(epochMilli);
        }
    }
}